<template>
	<!-- 评论 -->
	<view class="comment">
		<view class="commentnav">
			<text>评论区({{data.total}})</text>
			<view class="typeofcontent">
				<text :class="{active:sortType===1}"  :data-item="1">推荐</text>
				<text :class="{active:sortType===2}"  :data-item="2">最热</text>
				<text :class="{active:sortType===3}"  :data-item="3">最新</text>
			</view>

		</view>

		<scroll-view scroll-y="true" :style="{height:mainHeight +'px'}" @scrolltolower="getComment(1)"
			:scroll-top='scrollTop'>
			<view class="com" v-for="(item,index) in comments" :key="item.commentId">
				<view class="user">
					<view>
						<image :src="item.user.avatarUrl" mode="aspectFit" class="userimg"></image>
						<view class="userlist">
							<text class="name">{{item.user.nickname}}</text>
							<text class="date">{{getdate(item.time)}}</text>
						</view>
					</view>
					<view class="dianzan">
						<text>{{item.likedCount}}</text>
						<text class="iconfont .icon-pinglun"></text>
						<!-- <image src="../../static/images/dianzan.png" mode="widthFix"></image> -->
					</view>
				</view>
				<!-- 更多 -->
				<view class="content">
					<!-- 用户评论 -->
					<text>{{item.content}}</text>
				</view>
			</view>
			<view class="ageli"></view>
		</scroll-view>

	</view>
</template>

<script>
	const app = getApp()
	import {
		getComment
	} from '../../service/songs.js'
	export default {
		data() {
			return {
				sortType:1,
				data: {},
				comments: []
			}
		},
		onLoad() {
			getComment(app.globalData.id).then(res => {
				this.data = res
				this.comments = res.comments
			})
		},
		methods: {
			getdate(e) {
				let thisdate = new Date(e)
				let y = thisdate.getFullYear()
				let m = thisdate.getMonth() + 1
				let d = thisdate.getDate()
				let now = new Date()
				let nowy = now.getFullYear()
				if (y === nowy) {
					return (m < 10 ? "0" + m : m) + "月" + (d < 10 ? "0" + d : d) + '日'
				} else {
					return y + '年' + (m < 10 ? "0" + m : m) + "月" + (d < 10 ? "0" + d : d) + '日'
				}
			},
		}
	}
</script>

<style lang="less">

	.reply {
		font-size: 28rpx;
		padding-left: 20rpx;
		border-left: 3px solid #F5F5F5;
		width: 500rpx;

		.replyname {
			color: #007AFF;

			text {
				color: black;
			}
		}
	}

	.comment {
		width: 100%;
		position: absolute;
		z-index: 10086;
		background-color: #FFFFFF;

		.commentnav {
			height: 70rpx;
			line-height: 70rpx;
			font-size: 30rpx;
			padding-left: 30rpx;
			font-weight: bold;
			border-bottom: 1px solid #55aa7f;
			display: flex;
			justify-content: space-between;

			.typeofcontent {
				display: inline-block;
				margin-right: 20rpx;

				text {
					font-size: 30rpx;
					color: #808080;
					font-weight: normal;
					padding-left: 20rpx;
				}

				.active {
					font-weight: bold;
					color: black;
				}
			}
		}
	}

	.com {
		border-bottom: 1rpx solid #b0b0b0;

		.user {
			margin-top: 10rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 100rpx;

			.userimg {
				width: 60rpx;
				height: 60rpx;
				border-radius: 50rpx;
				margin-left: 30rpx;
				vertical-align: middle;
			}

			.userlist {
				padding-left: 20rpx;
				display: inline-block;
				vertical-align: middle;

				text {
					display: block;
				}

				.name {
					font-size: 30rpx;
					color: #515151;
					font-size: 28rpx;
				}

				.date {
					font-size: 25rpx;
					color: #808080;
				}
			}

			.dianzan {
				display: inline-block;
				margin-right: 15rpx;
				text {
					font-size: 28rpx;
					color: #808080;
					margin-right: 15rpx;
				}

				.icon-dianzan {
					padding-left: 10rpx;
					padding-right: 25rpx;
				}
			}
		}

		.content {
			margin-left: 110rpx;
			padding-right: 20rpx;
			font-size: 28rpx;
			line-height: 42rpx;
			width: 600rpx;
			border-bottom: 1px solid #F5F5F5;
			padding-bottom: 10rpx;

			.morecontent {
				font-size: 25rpx;
				display: block;
				color: #007AFF;

				.icon-xiangyou {
					font-size: 25rpx;
				}
			}
		}

	}
</style>